<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:include="include :: appHeader"></head>
<body id="history-body" ontouchstart>
<div class="weui-form-preview">
    <div class="weui-form-preview__hd">
        <div class="weui-form-preview__item">
            <label class="weui-form-preview__label">生产令号</label>
            <b class="weui-form-preview__item" th:text="${sheet.prodNo}">2020F058-01</b>
        </div>
        <div class="weui-form-preview__item">
            <label class="weui-form-preview__label">图号</label>
            <b class="weui-form-preview__item" th:text="${sheet.drawNo}">RLFSSB4T.2.1.2-1</b>
        </div>
        <div class="weui-form-preview__item">
            <label class="weui-form-preview__label">零件名称</label>
            <b class="weui-form-preview__item" th:text="${sheet.drawName}">钢板 44×44×20</b>
        </div>
        <div class="weui-form-preview__item">
            <label class="weui-form-preview__label">零件数量</label>
            <b class="weui-form-preview__item" th:text="${sheet.drawNum}">10</b>
        </div>
    </div>
</div>
<h2 th:if="${#lists.isEmpty(list) and #lists.isEmpty(completeList)}" style="margin-top: 16px;text-align: center">查无记录</h2>
<h2 th:if="${#lists.isEmpty(list)} and ${completeList.size() > 0}" style="margin-top: 16px;text-align: center">该零件已全部转序</h2>
<div class="weui-cells">
    <div th:each="r : ${list}">
        <form>
            <input type="hidden" name="id" th:value="${r.id}">
            <div class="weui-cell">
                <div class="weui-cell__bd">
                    <p th:text="${r.route}"></p>
                </div>
                <div class="weui-cell__ft">
                    <div class="weui-count">
                        <a class="weui-count__btn weui-count__decrease"></a>
                        <input id="weui-count__number" class="weui-count__number" type="number" name="applyNum" value="1" th:data="${r.mayApplyNum}" th:value="${r.mayApplyNum}" onchange="changeDefVal()">
                        <a class="weui-count__btn weui-count__increase"></a>
                    </div>
                </div>
            </div>
            <div class="button_sp_area" style="text-align: center;">
                <a href="javascript:void(0);" class="weui-btn weui-btn_mini weui-btn_primary btn-apply">申请质检</a>
            </div>
        </form>
    </div>
</div>

<div th:include="include :: appFooter"></div>
<script th:inline="javascript">

    $(function () {

        $('.weui-count__decrease').click(function (e) {
            let $input = $(e.currentTarget).parent().find('.weui-count__number');
            let number = parseInt($input.val() || "0") - 1
            if (number < 1) number = 1;
            $input.val(number)
        })

        $('.weui-count__increase').click(function (e) {
            let $input = $(e.currentTarget).parent().find('.weui-count__number');
            let max = $input.attr("data");
            let number = parseInt($input.val() || "0") + 1
            if (number > max) number = max;
            $input.val(number)
        })

        $('.btn-apply').click(function (e) {
            let $form = $(e.currentTarget).parents("form");
            $.operate.submit({
                url: ctx + 'assembly/apply',
                data: new FormData($form[0]),
                fun: function (res) {
                    if(res.type === 'SUCCESS' ){
                        $.box.toptip_s(res.msg);
                        location.href = ctx + "index";
                    }else{
                        $.box.toptip_w(res.msg);
                    }
                }
            });
        })

    })

    /**
     * 更改数量函数
     * 徐一贺
     */
    function changeDefVal(){
        let max = document.getElementById("weui-count__number").getAttribute("data")
        let number = document.getElementById("weui-count__number").value;
        if (parseInt(number) < 1) {
            number = 1;
        }
        if (parseInt(number) > parseInt(max)) {
            number = max;
        }
        document.getElementById("weui-count__number").value=number;
    }
</script>
</body>
</html>